# -*- encoding: utf-8 -*-
from django.db import models
from django.utils.translation import ugettext_lazy as _

from multilingual.translation import TranslationModel

from modulo.groups.models import Group
from modulo.map.models import Map
from modulo.page.models import Section

class Schedule(models.Model):
    CONCERT_DAYS = (('friday',   _(u'Vendredi')),
                    ('saturday', _(u'Samedi')),
                    ('sunday',   _(u'Dimanche')),
                    ('monday',   _(u'Lundi')),)

    section = models.ForeignKey(Section, related_name="day",
                                limit_choices_to = {'app': 'schedule'},
                                help_text=_(u"Selection de la rubrique contenant cet horaire."))

    day = models.CharField(_(u'Jour'), choices=CONCERT_DAYS, max_length=8)

    def __unicode__(self):
        from templatetags.schedule_extras import day
        return u"%s" % day(self.day)

    class Meta:
        verbose_name = _('programme')


class Concert(models.Model):
    PLAYING_TIME = ((30,  '30mn'),
                    (60,  '1h'),
                    (90,  '1h30'),
                    (120, '2h'),
                    (180, '3h'),
                    (210, '3h30'),)

    day = models.ForeignKey(Schedule, verbose_name=_(u'Jour'), related_name="concerts")

    scene = models.ForeignKey(Map, related_name="concerts")
    
    group = models.ForeignKey(Group, related_name="concerts", null=True, blank=True)
    
    starting_time = models.TimeField(_('Horaire de début'))
    
    playing_time = models.IntegerField(_('Durée'), choices=PLAYING_TIME, default=60)

    conf = models.BooleanField(_(u'Conférence ?'), default=False)

    class Meta:
        ordering = ['day', 'scene', 'starting_time']
        verbose_name = _('concert')

    class Translation(TranslationModel):
        name = models.CharField(_(u'nom'), max_length=30, blank=True)
        description = models.CharField(_(u'description'), max_length=30, blank=True)

    def get_absolute_url(self):
        return u"%s" % self.group.get_absolute_url
    
    def __unicode__(self):
        retour = u"%s - %s : "% (self.day, self.scene)
        if self.name:
            retour += u"%s - " % self.name
        if self.group:
            retour += u"%s - " % self.group
        retour += u"%s pour %s mn" % (self.starting_time, self.playing_time)
        return retour
